package oj;

import java.util.Scanner;

/**
 * @author 郝文雪
 * @date 2022/7/14 12:46
 * @Description Test
 */
public class Day16扑克牌大小 {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        String card="345678910JQKA2jokerJOKER";
        while(sc.hasNext()){
            String str=sc.nextLine();
            if(str.contains("joker JOKER")){
                System.out.println("joker JOKER");
            }else{
                String[] s=str.split("-");
                String[] left=s[0].split(" ");
                String[] right=s[1].split(" ");
                if(left.length==4 && right.length!=4){
                    System.out.println(s[0]);
                }else if(left.length!=4 && right.length==4){
                    System.out.println(s[1]);
                }else if(left.length==right.length){
                    String card2=card.indexOf(left[0])>card.indexOf(right[0])?s[0]:s[1];
                    System.out.println(card2);
                }else{
                    System.out.println("ERROR");
                }
            }
        }
    }
}
